/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import interfaces.Lager_VareInterface;
import interfaces.VareInterface;
import java.awt.Color;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.border.LineBorder;
import utility.PriceFormater;

/**
 *
 * @author Jeppe
 */
public class VarePanel1 extends javax.swing.JPanel {

    private VareInterface vareInterface;
    private Lager_VareInterface lager_VareInterface;
    private VareBestillingsPanel varebestillingspanel;

    /**
     * Beregnet til grossistens varer
     */
    public VarePanel1(VareInterface vare, VareBestillingsPanel varebestillingspanel, boolean isAktiv) {
        initComponents();
        vareInterface = vare;
        this.varebestillingspanel = varebestillingspanel;
        try {
            titelLabel.setText(vareInterface.getTitel());
            antalLabel.setText(vareInterface.getAntalLager() + "");
            prisLabel.setText(PriceFormater.formaterPrisTilString(vareInterface.getSalgsPris()));
        } catch (RemoteException ex) {
            JOptionPane.showMessageDialog(this, "Der er opstået en fejl på forbindelsen mod serveren", "Remote-Exception", 0);
        }

        if (isAktiv) {
            setBorder(new LineBorder(Color.black, 2));
        }
    }

    public VarePanel1(Lager_VareInterface lager_VareInterface, VareBestillingsPanel varebestillingspanel, boolean isAktiv) {
        initComponents();
        this.lager_VareInterface = lager_VareInterface;
        this.varebestillingspanel = varebestillingspanel;

        try {
            vareInterface = lager_VareInterface.getVare();
            titelLabel.setText(vareInterface.getTitel());
            antalLabel.setText(lager_VareInterface.getAntal() + "");
            prisLabel.setText(PriceFormater.formaterPrisTilString(lager_VareInterface.getSalgsPris()));
        } catch (RemoteException ex) {
            JOptionPane.showMessageDialog(this, "Der er opstået en fejl på forbindelsen mod serveren", "Remote-Exception", 0);
        }
        if (isAktiv) {
            setBorder(new LineBorder(Color.black, 2));
        }
    }

    private void setLabels() {
        try {
            titelLabel.setText(vareInterface.getTitel());
            antalLabel.setText(vareInterface.getAntalLager() + "");
            prisLabel.setText(PriceFormater.formaterPrisTilString(vareInterface.getSalgsPris()));
        } catch (RemoteException ex) {
            JOptionPane.showMessageDialog(this, "Der er opstået en fejl på forbindelsen mod serveren", "Remote-Exception", 0);
        }
    }

    public VareInterface getVareInterface() {
        return vareInterface;
    }
    
    public void setVareAgain(VareInterface vare){
        this.vareInterface = vare;
        setLabels();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        titelLabel = new javax.swing.JLabel();
        antalLabel = new javax.swing.JLabel();
        prisLabel = new javax.swing.JLabel();

        setBorder(javax.swing.BorderFactory.createEtchedBorder());
        setLayout(null);

        jButton1.setText("  ");
        jButton1.setContentAreaFilled(false);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        add(jButton1);
        jButton1.setBounds(0, 0, 280, 40);

        titelLabel.setText("varetitel");
        add(titelLabel);
        titelLabel.setBounds(10, 11, 90, 14);

        antalLabel.setText("antal");
        add(antalLabel);
        antalLabel.setBounds(110, 10, 60, 14);

        prisLabel.setText("pris");
        add(prisLabel);
        prisLabel.setBounds(190, 10, 80, 14);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        varebestillingspanel.setAktivVare(vareInterface);
    }//GEN-LAST:event_jButton1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel antalLabel;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel prisLabel;
    private javax.swing.JLabel titelLabel;
    // End of variables declaration//GEN-END:variables
}
